#include<stdio.h>
#include<conio.h>
typedef struct Int{
    long value;
    Int *prev,*next;
};
Int *arr[100006];
Int *list=new Int;
long n,k;
void init(){
    long i;
    Int *a1=new Int;
    (*a1).value=1;
    (*a1).prev=list;
    (*a1).next=NULL;
    arr[1]=a1;
    (*list).next=a1;
    for(i=2;i<=n+1;i++){
        Int *a2=new Int;
        (*a2).value=i;
        (*a2).prev=a1;
        (*a2).next=NULL;
        (*a1).next=a2;
        a1=a2;
        arr[i]=a1;
    }
}
void shuffle(long from,long to){
    (*((*arr[from]).prev)).next=(*arr[from]).next;
    (*((*arr[from]).next)).prev=(*arr[from]).prev;
    
    (*arr[from]).prev=(*arr[to]).prev;
    (*arr[from]).next=arr[to];
    (*(*arr[from]).prev).next=arr[from];
    (*arr[to]).prev=arr[from];
}
void process(){
    FILE *fp=fopen("SHUFFLE.INP","r");
    fscanf(fp,"%ld%ld",&n,&k);
    init();
    long i,u,v;
    for(i=1;i<=n;i++){
        fscanf(fp,"%ld%ld",&u,&v);
        
        if(u!=v && u!=0 && v!=0)
            shuffle(u,v);
    }
    fclose(fp);
}
void output(){
    FILE *fp=fopen("SHUFFLE.OUT","w");
    Int *a=(*list).next;
    long i=0;
    do{
        i++;
        fprintf(fp,"%ld",(*a).value);
        if(i<n)fprintf(fp," ");
        a=(*a).next;
        
    }while(i<n);
    fclose(fp);
}
int main(){
    process();
    output();
    return 0;
}
